package com.google.android.material.bottomsheet;


import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;

/**
 * 用于主题详情中
 * 当设置状态为隐藏的时候，不能直接调用setState(BottomSheetBehavior.STATE_HIDDEN)
 * 否则 当软键盘打开的时候，并不能完全隐藏掉 commentListView
 *
 * @param <V>
 */
public class BottomSheetBehaviorV2<V extends View> extends BottomSheetBehavior {
    private static final String TAG = "BottomSheetBehaviorV1";
    private int downX;
    private int downY;
    private boolean setHiddenAfterOnLayoutChild;

    public BottomSheetBehaviorV2() {
    }

    public BottomSheetBehaviorV2(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public static <V extends View> BottomSheetBehaviorV2<V> fromV2(V view) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        if (!(params instanceof CoordinatorLayout.LayoutParams)) {
            throw new IllegalArgumentException("The view is not a child of CoordinatorLayout");
        } else {
            CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) params).getBehavior();
            if (!(behavior instanceof BottomSheetBehaviorV2)) {
                throw new IllegalArgumentException("The view is not associated with BottomSheetBehavior");
            } else {
                return (BottomSheetBehaviorV2) behavior;
            }
        }
    }


    /**
     * 隐藏CommentListView 避免在软键盘打开的情况下，无法完全滑动到屏幕底部
     *
     * @param parentHeight
     */
    public void setStateHidden(int parentHeight) {
        this.parentHeight = parentHeight;
        setState(BottomSheetBehavior.STATE_HIDDEN);
    }


}
